package com.liao.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.liao.mapper.GoodstypeMapper;
import com.liao.po.Goods;
import com.liao.po.Goodstype;
import com.liao.po.User;
import com.liao.service.GoodstypeService;
import com.liao.utils.PageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author itcast
 */
@Slf4j
@Service
public class GoodstypeServiceImpl extends ServiceImpl<GoodstypeMapper, Goodstype> implements GoodstypeService {
    private Integer page = 1;
    private Integer limit = 10;

    @Override
    public PageUtils queryPageByCodition(Map<String, Object> params) {
        LambdaQueryWrapper<Goodstype> queryWrapper = Wrappers.lambdaQuery();

        String pagekey = (String) params.get("page");
        if (!StringUtils.isEmpty(pagekey) && !"0".equalsIgnoreCase(pagekey)) {
            page = Integer.parseInt(pagekey);
        }

        String limitkey = (String) params.get("limit");
        if (!StringUtils.isEmpty(limitkey) && !"0".equalsIgnoreCase(limitkey)) {
            limit = Integer.parseInt(limitkey);
        }

        String searchKey = (String) params.get("searchkey");
        if (!StringUtils.isEmpty(searchKey)) {
            queryWrapper.like(Goodstype::getTname, searchKey);
        }

        Page<Goodstype> goodsPage = new Page<>(page, limit);
        IPage<Goodstype> goodsIPage = this.baseMapper.selectPage(goodsPage, queryWrapper);
        System.out.println("总页数： " + goodsIPage.getPages());
        System.out.println("总记录数： " + goodsIPage.getTotal());
        goodsIPage.getRecords().forEach(System.out::println);
        return new PageUtils(goodsIPage);
    }
}
